#ifndef XMLINTERFACE_H
#define XMLINTERFACE_H

#include <QObject>
#include <QtXml>
#include <QTemporaryFile>
#include <vector>
#include "propdata.h"

class XMLInterface : public QObject
{
#define DATAPATH ("/sdcard/artour/")

    Q_OBJECT
private:
    QDomDocument *doc;
    QDomElement root;
    PropData *minimap;
    std::vector<PropData *> props;
    QTemporaryFile *tmpXML;

public:
    explicit XMLInterface(QObject *parent = 0);

    ~XMLInterface();

    bool buildXML(QString path = "", bool keepLocalPaths = false);

    void readXML(QString path);

    PropData * getPropByName(QString name);

    void removePropByName(QString name);

    void removeAllProps();

    // should be called when a device disconnects
    void removeDeviceProps();

    std::vector<PropData *> getAllProps();

    void setMinimap(PropData *mmap);
    PropData* getMinimap();
    void clearMinimap();

    QString translatePath(QString systemPath, QString devicePathFolder = "");

    QString getTmpXmlFile();

signals:
    void propAdded(PropData *prop, bool updateLocal);
    void propRemoved(QString pName);
    void propRemovedXmlOnly(QString pName);
    void minimapAdded(PropData *map, bool updateLocal);
    void propAudioScriptRequest(PropData *prop);

public slots:
    void addProp(PropData *prop);
    void addPropFromXML(PropData *prop);
    void setMinimapFromXML(PropData *prop);

};

#endif // XMLINTERFACE_H
